/***************************************************************************
 *   smd.h - SMD Loader                                                    *
 *   Copyright (C) 2008 by cmaster.matso                                   *
 *   cmaster.matso@gmail.com                                               *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

#ifndef _SMD_H
#define _SMD_H

#ifdef __cplusplus
extern "C" {
#endif

#include "../../math/src/mgpi_math.h"

#define HL_MODEL_VERSION         1
#define SMD_VERSION              "version"
#define SMD_END                  "end"
#define SMD_NODES                "nodes"
#define SMD_SCELETON             "sceleton"
#define SMD_TIME                 "time"
#define SMD_TRIANGLES            "triangles"
#define SMD_VERTEXANIMATION      "vertexanimation"

#pragma pack(push,1)

    struct _smd_bone {
        int id; /* if root equal to -1 */
        char *name;
        int parent_id;
    };

    struct _smd_pose {
        int bone_id;
        float position[3];
        float rotation[3];
    };

    struct _smd_vertex {
        int parent_bone_id;
        float position[3];
        float normal[3];
        float tex_coords[2];
        float bone_weight;
        int bone_id;
        int num_bwid; /* ???? */
    };

    struct _vta_vertex {
        float vertex_time;
        int vertex_id;
        float position[3];
        float normal[3];
    };

    struct _smd_triangle {
        GLuint tex_id;
        char *face_tex_name;
        /*struct smd_vertex_t vertices[3];*/
        int vertices_index[3];
    };

    struct _smd_model {
        int version; /* should be 1 (for both HL and HL2 models)*/

        int num_bones;
        int num_poses;
        int num_triangles;
        int num_vertices; /* = 3*num_triangles */

        struct _smd_bone *model_bones;
        struct _smd_pose *model_poses;
        struct _smd_triangle *model_triangles;
        struct _smd_vertex *model_vertices;
        struct _vta_vertex *vta_model_vertices;
    };

#pragma pack(pop)

    typedef struct _smd_model smd_model_t;

    void MGPI_API gsubReadSMDModel(const char *, struct _smd_model *);
    void MGPI_API gsubFreeSMDModel(struct _smd_model *);
    void MGPI_API gsubRenderSMDModel(struct _smd_model *);
    void MGPI_API gsubAnimateSMD(struct _smd_model *);

#ifdef __cplusplus
}
#endif

#endif
